package com.rabc.framework;

import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class AsyncManager {


    // 单例实例
    private static final AsyncManager instance = new AsyncManager();

    // 操作延迟时间（默认10毫秒）
    private final int OPERATE_DELAY_TIME = 10;

    // 线程池
    private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(5);

    // 私有构造函数，防止外部实例化
    private AsyncManager() {}

    // 获取单例实例
    public static AsyncManager getInstance() {
        return instance;
    }

    /**
     * 关闭异步任务管理器
     */
    /**
     * 执行任务
     *
     * @param task 任务
     */
    public void execute(TimerTask task) {
        executor.schedule(task, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS);
    }

}